/**
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ro.uvt.sp.lp.hw1.beermugs.visual;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;


/**
 * calsa care deseneaza halbele
 * @author LP
 *
 */
public class BeerMugsCanvas extends Canvas{

	 /**
	 * 
	 */
	private static final long serialVersionUID = 297766115705963617L;
		private final int high;
	    private final int wide;
	    private GeneralPath mugX;
	    private GeneralPath mugY;
	    private Rectangle2D.Double beerX;
	    private Rectangle2D.Double beerY;
	    
	    public BeerMugsCanvas(BeerMugState wState){
	        super(wState, new BeerMugState());
	        
	        wide = 600;
	        high = 400;
	        
	        setLayout(new FlowLayout());
	        setSize(getPreferredSize());
	        makeMugs();
	        makeBeer();
	        repaint();
	    }
	    
	  
	    public void paintComponent(Graphics g){
	        Graphics2D g2 = (Graphics2D) g;
	        g2.setStroke(new BasicStroke(4));
	        g2.draw(mugX);
	        g2.draw(mugY);
	        g2.setFont(new Font(Font.MONOSPACED, Font.BOLD, 20));
	        g2.drawString(getXs(),(int) (.2*wide), (int) (.75*high));
	        g2.drawString(getYs(),(int) (.6*wide), (int) (.75*high));
	        g2.setColor(Color.blue);
	        g2.fill(beerX);
	        g2.fill(beerY);
	    }
	    
	    
	    protected void makeObjects(){
	        makeMugs();
	        makeBeer();
	    }
	    
	    //deseneaza berea
	    private void makeBeer(){
	        beerX = new Rectangle2D.Double();
	        beerY = new Rectangle2D.Double();
	        
	        BeerMugState wState = (BeerMugState) getState();
	        if(wState.getXLvl() == 0){}
	        else if(wState.getXLvl() == 1){
	            beerX = new Rectangle2D.Double(.15*wide, .6*high,.2*wide, .1*high);
	        }
	        else if(wState.getXLvl() == 2){
	            beerX = new Rectangle2D.Double(.15*wide, .5*high,.2*wide, .2*high);
	        }
	        else if(wState.getXLvl() == 3){
	            beerX = new Rectangle2D.Double(.15*wide, .4*high, .2*wide, .3*high);
	        }
	        
	        if(wState.getYLvl() == 0){}
	        else if(wState.getYLvl() == 1){
	            beerY = new Rectangle2D.Double(.55*wide, .6*high,.2*wide, .1*high);
	        }
	        else if(wState.getYLvl() == 2){
	            beerY = new Rectangle2D.Double(.55*wide, .5*high,.2*wide, .2*high);
	        }
	        else if(wState.getYLvl() == 3){
	            beerY = new Rectangle2D.Double(.55*wide, .4*high, .2*wide, .3*high);
	        }
	        else if(wState.getYLvl() == 4){
	            beerY = new Rectangle2D.Double(.55*wide, .3*high, .2*wide, .4*high);
	        }
	    }
	    
	    
	    public void render(){
	        repaint();
	    }
	    
	 
	    
	    //deseneaza halbe
	    private void makeMugs(){
	        mugX = new GeneralPath();
	        mugY = new GeneralPath();
	        
	        mugX.moveTo(.15*wide, .4*high);
	        mugX.lineTo(.15*wide, .7*high);
	        mugX.lineTo(.35*wide, .7*high);
	        mugX.lineTo(.35*wide, .4*high);
	        
	        mugY.moveTo(.55*wide, .3*high);
	        mugY.lineTo(.55*wide, .7*high);
	        mugY.lineTo(.75*wide, .7*high);
	        mugY.lineTo(.75*wide, .3*high);
	        
	    }
	    
	    private String getYs(){
	    	BeerMugState wst = (BeerMugState) getState();
	        Integer temp = wst.getYLvl();
	        return "Y(" + temp.toString() + ")";
	    }
	    
	    
	    
	    private String getXs(){
	    	BeerMugState wst = (BeerMugState) getState();
	        Integer temp = wst.getXLvl();
	        return "X(" + temp.toString() + ")";
	    }
	    
	    
	    public Dimension getPreferredSize() {
	        return new Dimension(wide, high);
	    }
	    

	    public void setSate(BeerMugState s){
	    	
	    }
	    
}
